package cn.edu.xhu.library_management.book.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.edu.xhu.library_management.book.entity.LmBookCategory;
import cn.edu.xhu.library_management.book.service.LmBookCategoryService;
import cn.edu.xhu.library_management.book.mapper.LmBookCategoryMapper;
import org.springframework.stereotype.Service;

import java.util.*;

/**
* @author 21086
* @description 针对表【lm_book_category】的数据库操作Service实现
* @createDate 2023-03-14 09:46:16
*/
@Service
public class LmBookCategoryServiceImpl extends ServiceImpl<LmBookCategoryMapper, LmBookCategory>
    implements LmBookCategoryService{


    @Override
    public List<LmBookCategory> findCategoryByPId(Long pid) {
        QueryWrapper<LmBookCategory> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(LmBookCategory::getBcParantId,pid);
        return this.list(wrapper);
    }

    @Override
    public List<LmBookCategory> searchCategoryByCodeOrName(Integer type, String content) {
        List<LmBookCategory> categories = new ArrayList<>();
        if (type == 1){
            // 通过code查询
            categories= this.list(new QueryWrapper<LmBookCategory>().lambda().like(LmBookCategory::getBcCode, content));
        }else {
            // 通过name查询
            categories= this.list(new QueryWrapper<LmBookCategory>().lambda().like(LmBookCategory::getBcName,content));
        }
        return categories;
    }


}




